package com.hxkcloud.patient.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;


/**
 * @Package: com.yipong.app.utils
 * @ClassName: SystemUtils.java
 * @Description:?????
 * @auther: allen_lee
 * @Date: 2016-2-25 ??5:31:15
 */

public class SystemUtils {

    /*
     * ???????
     */
    public static int getVersionCode(Context context) {
        // ??packagemanager???
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()?????????0?????????
        PackageInfo packInfo;
        try {
            packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            int versionCode = packInfo.versionCode;
            return versionCode;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
            return 0;
        }
    }

    /*
     * ?????????
     */
    public static String getIdentify_key(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getDeviceId();
    }

    /*
     * ??????????
     */
    public static String getNetwork_type(Context context) {
        if (WebUtils.isConnected()) {
            ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info = connectMgr.getActiveNetworkInfo();
            if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                return "2";
            } else {
                return "1";
            }
        } else {
            return "0";
        }
    }

}
